package com.wehealth;

import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class SideListFragment extends ListFragment {
	
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.side_list, null);
    }
 
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
 
        SampleAdapter adapter = new SampleAdapter(getActivity());
        adapter.add(new SampleItem("登录", R.drawable.ic_launcher));
        adapter.add(new SampleItem("疑问", R.drawable.ic_launcher));
        adapter.add(new SampleItem("右哼哼", R.drawable.ic_launcher));
        adapter.add(new SampleItem("晕", R.drawable.ic_launcher));

 
        setListAdapter(adapter);
    }
    
    public class SampleAdapter extends ArrayAdapter<SampleItem> {
        public SampleAdapter(Context context) {
            super(context, 0);
        }
 
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
        	
        	/*
            if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(
                        R.layout.row, null);
            }
            ImageView icon = (ImageView) convertView
                    .findViewById(R.id.row_icon);
            icon.setImageResource(getItem(position).iconRes);
            TextView title = (TextView) convertView
                    .findViewById(R.id.row_title);
            title.setText(getItem(position).tag);
            
             */
            return convertView;
        }
       
    }
    
    
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        Fragment newContent = null;
        switch (position) {
        case 0:
           // newContent = new MyFragment();
            break;
        case 1:
            //newContent = new MyFragment1();
            break;
  
        }
        if (newContent != null) {
            switchFragment(newContent);
        }
        super.onListItemClick(l, v, position, id);
    }
 
    private void switchFragment(Fragment fragment) {
        if (getActivity() == null) {
            return;
        }
        if (getActivity() instanceof MainActivity) {
            MainActivity fca = (MainActivity) getActivity();
           // fca.switchContent(fragment);
        }
    }
    
    private class SampleItem {
        public String tag;
        public int iconRes;
 
        public SampleItem(String tag, int iconRes) {
            this.tag = tag;
            this.iconRes = iconRes;
        }
    }
 
   

}
